package cn.mandifal.manager.controller;

import cn.mandifal.manager.service.SellerManagementService;
import cn.mandifal.pojo.DpSeller;
import com.alibaba.dubbo.config.annotation.Reference;
import entity.PageResult;
import entity.Result;
import entity.ResultCode;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商家管理 控制层
 * @author ws
 */
@RestController
@RequestMapping("/sellerManagementController")
public class SellerManagementController {
    @Reference
    private SellerManagementService sellerManagementService;

    /**
     * 查询所有商家
     * @param pageNum 页码
     * @param pageSize 页的大小
     * @return 分页结果
     */
    @RequestMapping("/findAllSeller")
    public PageResult findAllSeller(int pageNum,int pageSize){
        return sellerManagementService.findAllSeller(pageNum,pageSize);
    }

    /**
     * 查询商家详情
     * @param sellerid 商家 id
     * @return 返回查询结果
     */
    @RequestMapping("/findOneSeller")
    public DpSeller findOneSeller(String sellerid){
        return sellerManagementService.findOneSeller(sellerid);
    }

    /**
     * 修改商家状态
     * @param sellerid 商家 id
     * @param status 状态
     * @return 返回结果
     */
    @RequestMapping("/updateSellerStatus")
    public Result updateSellerStatus(String sellerid, String status){

        try {
            sellerManagementService.updateSellerStatus(sellerid,status);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed();
        }

    }

    /**
     * 条件查询
     * @param pageNum 页码
     * @param pageSize 页面大小
     * @param dpSeller 商家实体
     * @return 返回查询到的结果，分页
     */
    @RequestMapping("/search")
    public PageResult search(@RequestBody DpSeller dpSeller, int pageNum, int pageSize){
        return sellerManagementService.search(pageNum,pageSize,dpSeller);
    }
}
